<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>DOM注册事件</title>
  </head>
  <body>
    <div class="box1">注册一个事件</div>
    <script>
      // 1.获取要注册事件的DOM对象
      const box1 = document.querySelector(".box1");
      console.log(box1);
      // 2.给DOM对象注册事件
      box1.addEventListener("click", function () {
        console.log("点我变色");
        this.style.color = "red";
      });
    </script>
  </body>
</html>
